import Vue from "vue"
import Vuex from "vuex"
import axios from "axios"

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    // 用户信息对象
    userInfo: {}
  },
  getters: {},
  mutations: {
    updateUserinfo(state, userInfo) {
      state.userInfo = userInfo
    }
  },
  actions: {
    // 获取用户信息
    async getUserInfo(ctx) {
      const { data: res } = await axios("/my/userinfo")
      // ,{
      //   headers:{
      //     Authorization:localStorage.getItem("token")
      //   }
      // }
      // console.log(res);
      ctx.commit("updateUserinfo", res.data)
    }
  },
  modules: {}
})
